﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//Adding 
using System.Data;
using KPIS.DBM;
using KPIS.GERP.ESS.MODEL;

namespace KPIS.GERP.ESS.DAL
{
    public class D_FimMoneyReturn
    { 
        #region Public Methods

        public DataTable getMoneyReturnReport(string mnyReqSeq)
        {
            IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);

            string strSQL;
            DataTable dtb = null;

            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);

                dbManager.AddParameters(0, "@money_req_seq", mnyReqSeq);

                strSQL = "SELECT * FROM vwMoneyReturnReport WHERE money_req_seq like @money_req_seq";

                dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
            }
            catch (Exception ex)
            {
                throw new ArgumentException(ex.Message);
            }
            finally
            {
                dbManager.Dispose();
            }

            return dtb;
        }

        public DataTable getMoneyReturnReport(string mnyReqSeq,string clRefNo)
        {
            IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);

            string strSQL;
            DataTable dtb = null;

            try
            {
                dbManager.Open();
                dbManager.CreateParameters(2);

                dbManager.AddParameters(0, "@money_req_seq", mnyReqSeq);
                dbManager.AddParameters(1, "@ref_no", clRefNo);

                strSQL = "SELECT * FROM vwMoneyReturnReport WHERE money_req_seq = @money_req_seq";
                strSQL += clRefNo != "-" ? " AND return_seq = @ref_no":"";

                dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
            }
            catch (Exception ex)
            {
                throw new ArgumentException(ex.Message);
            }
            finally
            {
                dbManager.Dispose();
            }

            return dtb;
        }

        #endregion
    }
}
